<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>投保管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表编号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null,callback=null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insInsure/initList.do',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', width: 100, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstNm+'</span></a>';
                    }
                },
                {display: '支付表号', name: 'paySchNo', width: 180, align: 'left'},
                {display: '合同号', name: 'lsCntNo', width: 150, align: 'left'},
                {display: '业务类型', name: 'prjTypCdNm', width: 100, align: 'left'},
                {display: '供应商', name: 'splNm', minWidth: 120, align: 'left',
                    render:function (rowdata,rowindex,value) {
                        if(value){
                            return '<span class="gridTip" title="'+ value +'">'+ value +'</span>'
                        }
                }},
                {display: '产品名称', name: 'prdNm', width: 100, align: 'left'},
                {display: '单价', name: 'prdPrc', width: 100, align: 'right',
                    render:function(rowdata,rowindex,value){
                        return '&yen;'+FormatMoney(rowdata.prdPrc/100);
                    }
                },
                {display: '合格证号', name: 'certNo', minWidth: 100, align: 'center',
                    render:function(rowdata,rowindex,value){
                        if(rowdata.prjTypCd == "CDDYWUL" || rowdata.prjTypCd == "ESCJYD" || rowdata.prjTypCd == "OWNJYD") {  // 业务类型 车抵贷业务(线下)、二手车交易贷 取消合格证 REQ-3672
                            return "---";
                        }
                        if(rowdata.buOrgCd=='00000005' || rowdata.buOrgCd=='00000013'
                            || (rowdata.cstMgrOrgCd != null && rowdata.cstMgrOrgCd.indexOf('00000008') != -1)){
                            if(rowdata.buOrgCd=='00000013'){
                                if(rowdata.vinNo && rowdata.prdMdl && rowdata.gpsCardNo){
                                    return '<a href="javascript:;" onclick="prdDetail('+rowindex+')">'+rowdata.vinNo+'</a>';
                                }else{
                                    return '<a href="javascript:;" onclick="modifyPrdDtl('+rowindex+')">录合格证</a>';
                                }
                            }else if(rowdata.buOrgCd=='00000008'){
                                if(rowdata.vinNo && rowdata.engNo){
                                    return '<a href="javascript:;" onclick="prdDetail('+rowindex+')">'+rowdata.vinNo+'</a>';
                                }else{
                                    return '<a href="javascript:;" onclick="modifyPrdDtl('+rowindex+')">录合格证</a>';
                                }
                            }else{
                                if(rowdata.vinNo && rowdata.prdMdl && rowdata.engNo && rowdata.gpsCardNo){
                                    return '<a href="javascript:;" onclick="prdDetail('+rowindex+')">'+rowdata.vinNo+'</a>';
                                }else{
                                    return '<a href="javascript:;" onclick="modifyPrdDtl('+rowindex+')">录合格证</a>';
                                }
                            }
                        }else{
                            if(value){
                                return '<a href="javascript:;" onclick="detailBtn('+rowdata.actPrdId+','+rowdata.prjPrdDtlId+')">'+rowdata.certNo+'</a>';
                            }else{
                                return '<a href="javascript:;" onclick="addPrdCert('+rowdata.prjPrdDtlId+')">录合格证</a>';
                            }
                        }
                    }
                },
                {display: '投保状态', name: 'insStsCdNm', width: 90, align: 'center'},
                {display:"操作",width:150,align:'left',
                    render:function (rowdata,rowindex,value) {
                    	var a = '';
                    	var b = '';
                    	 a = '<a class="sq-button-hasicon" href="javascript:;" onclick="recordPlc(';
                    	 a += "'"+rowindex+"'";
                    	 a +=  ');"><i class="sqBtnIco_3"></i>录单</a>';
                    	 if (rowdata.insStsCdNm == '已投保'){
                    		 return a;
                    	 }else{
	                    	 b = '<a class="sq-button-hasicon" href="javascript:;" onclick="fqApplication(';
	                    	 b += "'"+rowindex+"'";
	                    	 b +=  ');"><i class="sqBtnIco_3"></i>分期申请</a>';
                    	 }
                    	return a+" "+b;
                        //return '<a class="sq-button-hasicon" href="javascript:;" onclick="recordPlc('+rowindex+');"><i class="sqBtnIco_3"></i>录单</a>';
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            checkbox:true,
            isSingleCheck:true,
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

    });

    //录单
    function recordPlc(_rowId){
        var row=grid.getRow(_rowId);
        if(row.prjTypCd != "CDDYWUL" && row.prjTypCd != "ESCJYD" && row.prjTypCd != "OWNJYD") {  // 业务类型 车抵贷业务(线下)、二手车交易贷 取消合格证 REQ-3672
            if (row.buOrgCd == '00000005' || row.buOrgCd == '00000008' || row.buOrgCd == '00000013') {
                if (row.buOrgCd == '00000013') {
                    if (!row.vinNo || !row.prdMdl || !row.gpsCardNo) {
                        $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                        return;
                    }
                } else if (row.buOrgCd == '00000008') {
                    if (!row.vinNo || !row.engNo) {
                        $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                        return;
                    }
                } else {
                    if (!row.vinNo || !row.prdMdl || !row.engNo || !row.gpsCardNo) {
                        $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                        return;
                    }
                }
            } else {
                if (!row.certNo) {
                    $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                    return;
                }
            }
        }

        Add_navTab("InsPlcBscInfo_"+row.prjPrdDtlId, "新增保单", '<%=path%>/insurance/insPlcBscInfo/toAddPage.do?prjPrdDtlId='+row.prjPrdDtlId+'&paySchId='+row.paySchId+'&paySchNo='+row.paySchNo+'&cstId='+row.cstId+'&prjId='
            +row.prjId+'&contNo='+row.lsCntNo, callback);
    }

    //查询客户详情
    function showCstDtl(_cstId){
        Add_navTab("InsPlcCstBscInfo_"+_cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id='+_cstId, null);
    }

    //合格证详情
    function detailBtn(id,dtlId,buOrgCd){
        Add_navTab('tab_prj_prd_veh_info_detail'+id,'合格证详情','<%=path%>/project/prjprdvehinfo/toDetailPage.do?detailFlag=true&&id='+id+'&&dtlId='+dtlId);
    }

    //录入合格证
    function addPrdCert(dtlId){
        var noLinkButton = true;
        Add_navTab('tab_prj_prd_veh_info_add'+dtlId,'添加合格证','<%=path%>/project/prjprdvehinfo/toAddPage.do?detailFlag=false&&dtlId='+dtlId + "&noLinkButton=" + noLinkButton,callback);
    }

    //修改产品信息 产品型号、发动机型号、gps卡1、vin号
    function modifyPrdDtl(index){
        var row=grid.getRow(index);
        //Add_navTab("prjPrdDtlCarPrdInfo_"+row.prjPrdDtlId, "项目产品详情", '<%=path%>/project/prjprddtl/toModifyPrjPrdDtlCarPrdInfoPage.do?detailFlag=false&&dtlId='+row.prjPrdDtlId+'&&prdTypCd='+row.prdTypCd, callback);
        $.ligerDialog.open({  title: '修改车辆信息',height: 500,width: 1000, url:'<%=path%>/project/prjprddtl/toModifyPrjPrdDtlCarPrdInfoPage.do?detailFlag=false&&dtlId='+row.prjPrdDtlId+'&&prdTypCd='+row.prdTypCd,callback:callback});
    }
    //产品详情
    function prdDetail(index) {
        var row=grid.getRow(index);
        Add_navTab("prjPrdDtlCarPrdInfo_"+row.prjPrdDtlId, "项目产品详情", '<%=path%>/project/prjprddtl/toModifyPrjPrdDtlCarPrdInfoPage.do?detailFlag=true&&dtlId='+row.prjPrdDtlId+'&&prdTypCd='+row.prdTypCd, callback);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
	//分期申请
    function fqApplication(_rowId){
    	 var row=grid.getRow(_rowId);
         if(row.prjTypCd != "CDDYWUL" && row.prjTypCd != "ESCJYD" && row.prjTypCd != "OWNJYD") {  // 业务类型 车抵贷业务(线下)、二手车交易贷 取消合格证 REQ-3672
             if (row.buOrgCd == '00000005' || row.buOrgCd == '00000008' || row.buOrgCd == '00000013') {
                 if (row.buOrgCd == '00000013') {
                     if (!row.vinNo || !row.prdMdl || !row.gpsCardNo) {
                         $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                         return;
                     }
                 } else if (row.buOrgCd == '00000008') {
                     if (!row.vinNo || !row.engNo) {
                         $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                         return;
                     }
                 } else {
                     if (!row.vinNo || !row.prdMdl || !row.engNo || !row.gpsCardNo) {
                         $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                         return;
                     }
                 }
             } else {
                 if (!row.certNo) {
                     $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
                     return;
                 }
             }
         }
        var prjPrdDtlId = row.prjPrdDtlId;
        Add_navTab("fqApplication"+prjPrdDtlId, "分期申请", '<%=path%>/inscare/insapplication/toAddPage.do?prjPrdDtlId='+prjPrdDtlId, null);

    }
</script>

</body>
</html>
